// Create necesssary variables
gen cll = 417000
gen PaboveC =  (appraisal_amount - (cll/.8)) / 1000
gen HiP = appraisal_amount  > (cll/ .8)
gen notba = 1- tbaelig
gen slope = HiP* PaboveC

// LLPA bins
qui do "${code}/tba_elig/_LLPAbins.do" credit_score orig_loan_to_value
egen LLPAbin = group(credit_score_bin ltv_bin)

// sample selection

drop if agency_id ==1 & orig_ym <= ym(2011, 10)

keep if orig_loan_to_value <= 80
keep if abs(PaboveC) <= 150
keep if orig_loan_to_value <= origcombltv
keep if diff_debt_to_income == 0
keep if year <= 2012

// winsorizing
qui su orig_rate, d
replace orig_rate = . if inrange(orig_rate, `r(p1)', `r(p99)')==0

// regression spec

global FEs "FEzip=i.prop_zip_code FEym=i.orig_ym FEseller_id=i.seller_id_id FEllpa=i.LLPAbin" 
global controls "c.credit_score##c.credit_score##c.credit_score c.mtoi##c.mtoi##c.mtoi *Orig"

